package hlhj.fhp.checkpoint

import android.app.Application

import com.lzy.okgo.OkGo
import com.lzy.okgo.cookie.CookieJarImpl
import com.lzy.okgo.cookie.store.MemoryCookieStore
import com.lzy.okgo.interceptor.HttpLoggingInterceptor
import com.lzy.okgo.model.HttpHeaders
import com.tencent.bugly.Bugly
import com.tencent.bugly.beta.Beta
import hlhj.fhp.checkpoint.utils.SPHelper
import me.jessyan.autosize.AutoSizeConfig
import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit
import java.util.logging.Level

/**
 * Created by Never Fear   on 2018\11\6 0006.
 * Never More....
 *
 * 仅仅是想想
 *
 * 我的小奇迹
 * */

class MyApp : Application() {

    override fun onCreate() {
        super.onCreate()
        /*Okgo设置*/
        OkGo.getInstance().init(this)
        val httpHeaders = HttpHeaders()
        httpHeaders.put("Authorization","Bearer ${SPHelper.getToken(this)}")
        OkGo.getInstance().addCommonHeaders(httpHeaders)
        val builder = OkHttpClient.Builder()
        val loggingInterceptor = HttpLoggingInterceptor("OkGo")
        loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY)
        loggingInterceptor.setColorLevel(Level.INFO)
        builder.readTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS)
        builder.writeTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS)
        builder.connectTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS)
        builder.cookieJar(CookieJarImpl(MemoryCookieStore()))
        builder.addInterceptor(loggingInterceptor)
        OkGo.getInstance().okHttpClient = builder.build()

        /*Bugly*/
        Bugly.init(getApplicationContext(), "72479cdfaa", true);

        /*屏幕适配*/
        AutoSizeConfig.getInstance().setCustomFragment(true);

    }
}
